package com.smart.village.big.screen.controller.bigscreen;

import com.alibaba.fastjson.JSONObject;
import com.smart.village.big.screen.domain.AjaxResult;
import com.smart.village.big.screen.service.VolunteerTeamsService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.logging.Logger;

import static com.smart.village.big.screen.domain.AjaxResult.error;
import static com.smart.village.big.screen.domain.AjaxResult.success;

/**
 * 志愿团队类
 */
@Tag(name = "志愿服务队接口")
@RestController
@RequestMapping("/volunteer/teams")
public class VolunteerTeamsController {
    Logger logger = Logger.getLogger(VolunteerTeamsController.class.getName());

    @Autowired
    private VolunteerTeamsService volunteerTeamsService;

    @Operation(summary = "获取大屏 基层治理 志愿服务")
    @Parameters({
            @Parameter(name = "partyOrganizationSerialNumber", description = "下拉选择的最底级的党组织，默认传漠河市党委")
    })
    @GetMapping("getVolunteer")
    @ResponseBody
    public AjaxResult getVolunteer(
            @RequestParam(required = false, defaultValue = "") String partyOrganizationSerialNumber) {
        try {
            JSONObject resultJson = volunteerTeamsService.getVolunteer(partyOrganizationSerialNumber);
            return success(resultJson);
        } catch (Exception e) {
            e.printStackTrace();
            logger.severe(e.getMessage());
            return error("程序错误请联系系统管理员");
        }
    }

    @Operation(summary = "获取大屏 基层治理 志愿服务-详情")
    @Parameters({
            @Parameter(name = "volunteerTeamSerialNumber", description = "志愿服务队序列号")
    })
    @GetMapping("getVolunteerDetail")
    @ResponseBody
    public AjaxResult getVolunteerDetail(
            @RequestParam(required = false, defaultValue = "") String volunteerTeamSerialNumber) {
        try {
            JSONObject resultJson = volunteerTeamsService.getVolunteerDetail(volunteerTeamSerialNumber);
            return success(resultJson);
        } catch (Exception e) {
            e.printStackTrace();
            logger.severe(e.getMessage());
            return error("程序错误请联系系统管理员");
        }
    }

    @Operation(summary = "获取大屏 基层治理 志愿服务活动-详情")
    @Parameters({
            @Parameter(name = "volunteerTeamsActivitiesSerialNumber", description = "志愿服务活动序列号")
    })
    @GetMapping("getVolunteerTeamsActivitiesDetail")
    @ResponseBody
    public AjaxResult getVolunteerTeamsActivitiesDetail(
            @RequestParam(required = false, defaultValue = "") String volunteerTeamsActivitiesSerialNumber) {
        try {
            JSONObject resultJson = volunteerTeamsService.getVolunteerTeamsActivitiesDetail(volunteerTeamsActivitiesSerialNumber);
            return success(resultJson);
        } catch (Exception e) {
            e.printStackTrace();
            logger.severe(e.getMessage());
            return error("程序错误请联系系统管理员");
        }
    }
}
